PATHMac OS 8 and 9 Developer Documentation > Human Interface Toolbox > Window Manager >

Programming With the Mac OS 8.5 Window Manager


Responding to Suspend and Resume Events

The Event Manager function WaitNextEvent returns a suspend event when your application is about to be switched to the background. WaitNextEvent returns a resume event when your application becomes the foreground process again.

Upon receiving a suspend event, your application should deactivate the front window and hide any floating windows. Upon receiving a resume event, your application should activate the front window and restore any windows to the state the user left them in at the time of the previous suspend event. For example, your application should show scroll bars and any floating windows. Listing 2-8 provides an example of how your application can respond to a suspend or resume event by calling the Window Manager functions HideFloatingWindows and ShowFloatingWindows to hide or show its floating windows, respectively.

IMPORTANT

The HideFloatingWindows and ShowFloatingWindows functions are supported under Mac OS 8.6 and later.

Listing 2-8 Hiding and showing floating windows

case suspendResumeMessage:
{
    // The message field of the EventRecord indicates whether you are
    // activating (resumeFlag is 1) or deactivating (resumeFlag is 0)

    Boolean becomingActive = (pEvent->message & resumeFlag) != 0;

    // The first document window should be activated or deactivated
    // in response to a suspendResumeMessage, since no other explicit
    // activate message will be sent to your application

    WindowPtr pWindow = FrontNonFloatingWindow();
    if (pWindow != NULL)
        MyHandleActivateDeactivateEvent(pWindow, becomingActive);

    // Human interface standards specify that floating windows be
    // shown when your application becomes active, and hidden while
    // it is inactive

    if (becomingActive)
        (void) ShowFloatingWindows();
    else
        (void) HideFloatingWindows();
    break;
}


© 1999 Apple Computer, Inc. – (Last Updated 18 March 99)